import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog';
const request = require("../../../utils/request")
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkDays:[
      // '2021-5-2',
      // '2021-5-3',
      // '2021-5-4',
      // '2021-5-5',
      // '2021-5-7',
      // '2021-5-9',
      // '2021-6-2',
      // '2021-6-4'
    ]
  },
  dailyCheck()
  {
    var that = this
    Dialog.confirm({
      message: '今日打卡',
    })
      .then(async () => {
        const today = new Date()
        const curDay = today.getDate();
        const curMonth = today.getMonth()+1;
        const curYear = today.getFullYear();
        const checkDays = this.data.checkDays
        that.setData({
          checkDays:[...checkDays,curYear+'-'+curMonth+'-'+curDay]
        })

        //发送网络请求
        let res = await request.dailyCheckInterface(curYear+'-'+curMonth+'-'+curDay,app.globalData.openid,'add')
        // console.log(res)
      })
      .catch(() => {
        // on cancel
      });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
    let res =await request.dailyCheckInterface(null,app.globalData.openid,'getAll')
    let checkDays=[]
    res.data.data.value.map((item)=>{
      checkDays.push(item.clock)
    })
    // console.log(checkDays)
    this.setData({
      checkDays
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow:async function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})